package com.xwh.article.controller;

import com.xwh.article.entity.SoftwareVersion;
import com.xwh.article.service.SoftwareVersionService;
import com.xwh.core.controller.BaseController;
import com.xwh.core.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xwh
 **/

@RequiredArgsConstructor
@RestController
@RequestMapping("/softwareVersion")
@Tag(name = "应用:软件版本管理")
@Slf4j
public class SoftwareVersionController extends BaseController {

    final SoftwareVersionService softwareVersionService;

    @Operation(summary = "新增一个软件版本")
    @PostMapping()
    public Result save(@RequestBody SoftwareVersion softwareVersion) {
        softwareVersionService.add(softwareVersion);
        return success();
    }

    @Operation(summary = "删除一个软件版本")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        softwareVersionService.removeById(id);
        return success();
    }

    @Operation(summary = "修改一个软件版本")
    @PutMapping("/update")
    public Result update(@RequestBody SoftwareVersion softwareVersion) {
        softwareVersionService.updateById(softwareVersion);
        return success();
    }

    @Operation(summary = "获取软件版本列表")
    @GetMapping("/list/{softwareId}")
    public Result list(@PathVariable String softwareId) {
        List<SoftwareVersion> softwareVersions = softwareVersionService.listBySoftwareId(softwareId);
        return success().add(softwareVersions);
    }

}
